const mongoose = require('mongoose')
const Schema = mongoose.Schema
const ResourceSchemaConfig = {
  versionKey: false,
  timestamps: {
    createdAt: 'created_at',
    updatedAt: false
  }
}

const ResourceSchema = new Schema({
  name: String,
  kb_size: { type: Number, min: 0 },
  ext: String,
  savedFileName: String,
  download_times: { type: Number, min: 0, default: 0 },
  delete: { type: Boolean, default: false },
  upload: { type: Schema.Types.ObjectId, ref: 'User' },
  team: { type: Schema.Types.ObjectId, ref: 'Team' }
}, ResourceSchemaConfig)

ResourceSchema.index({ team: 1 })

exports = module.exports = ResourceSchema
